]> Git — Sourcephile - julm/books.git/blob - calibre/J. K. Rowling/Harry Potter and the Philosopher's Stone (484)/filter
init
[julm/books.git] / calibre / J. K. Rowling / Harry Potter and the Philosopher's Stone (484) / filter
1 #!/usr/bin/env nix
2 #! nix shell --impure --expr ``
3 #! nix with (builtins.getFlake "git+file://${toString ./../..}/..").packages.${builtins.currentSystem};
4 #! nix [
5 #! nix (haskellPackages.ghcWithPackages (
6 #! nix haskellPackages: [
7 #! nix haskellPackages.pandoc-types
8 #! nix ]
9 #! nix ))
10 #! nix ]
11 #! nix ``
12 #! nix --command runhaskell
13
14 {-#LANGUAGE OverloadedStrings#-}
15 {-#LANGUAGE ViewPatterns #-}
16 import Text.Pandoc.JSON
17 import Data.List qualified as List
18 import Data.Text qualified as Text
19
20 main :: IO ()
21 main = toJSONFilter filt
22
23 filt :: Block -> Block
24 -- Put chapter images into the chapter
25 filt (Div as@(_, ["Section1"], _) es) = Div as (fixChapterImage es)
26 -- Remove useless images
27 filt (Para (Image _ _ ("Images/philos0.jpg", _):_)) = Para []
28 filt x = x
29
30 fixChapterImage (p@(Para
31 [ Span
32 ( _ , _ , _ )
33 (Image ( _ , _ , _ ) _ ( Text.isPrefixOf "Images/Chapter" -> True , _ )
34 :_)
35 ])
36 :h@Header{}
37 :xs
38 ) = h:p:xs
39 fixChapterImage (x:xs) = x:fixChapterImage xs
40 fixChapterImage [] = []
41
42 -- vim: syntax=haskell